package tum0r.data.algorithm;

import tum0r.misc.ArrayUtils;

/**
 * 工程: JavaTools<br>
 * 包: tum0r.data.algorithm<br>
 * 创建者: tum0r<br>
 * 创建时间: 2020/8/22 20:20<br>
 * <br>
 */
public class CombSort<T extends Comparable<T>> {

    public void sort(T[] array) {
        if (!ArrayUtils.isNullOrEmpty(array)) {
            double m = 1.3;
            boolean flag = false;
            int size = array.length;
            int n = size;
            T temp;
            while (n > 1 || flag) {
                n = Math.max((int) (n / m), 1);
                flag = true;
                for (int i = 0; i + n < size; i++) {
                    if (array[i].compareTo(array[i + n]) > 0) {
                        temp = array[i];
                        array[i] = array[i + n];
                        array[i + n] = temp;
                        flag = false;
                    }
                }
            }
        }
    }
}
